<template>
    <div>
        <el-form :model="ruleForm" :rules="rules" ref="form" label-width="120px" class="demo-ruleForm">
            <el-form-item label="应收款金额" prop="receivables">
                <el-input-number v-model="ruleForm.receivables" :controls="false"></el-input-number>
            </el-form-item>
            <el-form-item label="已收款金额" prop="amountReceived">
                <el-input-number :controls="false" v-model="ruleForm.amountReceived"></el-input-number>
            </el-form-item>
            <el-form-item label="税率" prop="rate">
                <el-input-number :precision="4" :controls="false" v-model="ruleForm.rate"></el-input-number>
            </el-form-item>
            <el-form-item label="收款条件" prop="term">
                <el-input v-model="ruleForm.term"></el-input>
            </el-form-item>
            <el-form-item label="应收款月份" prop="receMon">
                <el-date-picker
                        v-model="ruleForm.receMon"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="开票状态" prop="billStat">
                <el-select v-model="ruleForm.billStat" placeholder="请选择">
                    <el-option
                            v-for="item in statList"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="开票日期" prop="billTm">
                <el-date-picker
                        v-model="ruleForm.billTm"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择日期">
                </el-date-picker>
            </el-form-item>

        </el-form>
    </div>
</template>

<script>
    import {updateFinance}from '@/api/financeApi'
    export default {
        props: {
            params: {
                type: Object,
                default () {
                    return {}
                }
            }
        },
        data() {
            return {
                ruleForm: {
                    receivables: '',
                    amountReceived: '',
                    rate:'',
                    receMon: '',
                    billStat: '',
                    billTm:'',
                    term:''
                },
                statList:[
                    {
                        value: '0',
                        label: '未开票'
                    },
                    {
                        value: '1',
                        label: '已开票'
                    },
                ],
                rules: {
                    receMon: [
                        { required: true, message: '应收款月份不可为空', trigger: 'blur' },
                    ]
                }
            };
        },
        methods: {
            //提交
            submit() {
                return new Promise((resolve, reject) => {
                    this.$refs['form'].validate((valid) => {
                        if (valid){
                            updateFinance(this.ruleForm).then(res => {
                                resolve(res.data)
                            }).catch(e => {
                                console.log(e, 1111)
                                reject(e)
                                this.$message.error({
                                    message: '抱歉，操作遇到异常，请重试或联系管理员处理'
                                })
                            })
                        }else {
                            this.$message.error('业务校验未通过')
                            reject(new Error('业务校验失败'))
                        }
                    })
                })

            }
        },
        mounted() {
            this.ruleForm={...this.ruleForm,...this.params}
            console.log(this.ruleForm,11112222)
        }
    }
</script>

<style scoped>

</style>
